<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="component/heard :: head"></head>
<body>
<nav th:include="component/nav :: nav"></nav>
<script src="/js/mycard.js"></script>
<div class="container">
    <input type="text" id="cardId" class="form-control" th:value="${card?.id}" hidden>
    <div class="row">
        <div th:each="f : ${flowlist}" class="col-sm-4">
            <div class="card" style="margin-top: 10px;">
                <div class="card-body">
                    <h5 class="card-title" th:text="${f?.title}">标题</h5>
                    <p class="card-text" th:text="${f?.description}">内容</p>
                    <a th:href="@{'/card/flow/'+${f.id}}" class="link-secondary">查看</a>
                    <div class="form-check form-check-inline form-switch">
                        <input class="form-check-input fck" type="radio" name="flowRadio" th:id="${f.id}"
                               th:value="${f.id}" th:checked="${card?.fid} eq ${f.id}">
                        <label class="form-check-label" th:for="${f.id}">选择</label>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

</body>

<script>
    $(function () {
        $("input[name='flowRadio']").change(function () {
            let id = $("#cardId").val();
            let fid;
            $("input[name='flowRadio']").each(function () {
                let checked = $(this).is(":checked");
                if (checked) {
                    fid = $(this).attr("id");
                }
            });

            myCard.addTestInfo({id: id, fid: fid}, {
                success: function (obj) {
                    window.location.href = "/card/detail/" + id;
                    // alert("保存成功");
                },
                error: function (obj) {
                    alert("保存失败");
                }
            })
        })
    })
</script>
</html>


